package com.example.service;

import com.example.dao.BusSystemFileInfoDao;
import com.example.entity.BusSystemFileInfo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class BusSystemFileInfoService {

    @Value("${authority.info}")
    private String authorityInfo;

    @Resource
    private BusSystemFileInfoDao busSystemFileInfoDao;

    public BusSystemFileInfo add(BusSystemFileInfo busSystemFileInfo) {
        busSystemFileInfoDao.insertSelective(busSystemFileInfo);
        return busSystemFileInfo;
    }

    public void delete(Long id) {
        busSystemFileInfoDao.deleteByPrimaryKey(id);
    }

    public void update(BusSystemFileInfo busSystemFileInfo) {
        busSystemFileInfoDao.updateByPrimaryKeySelective(busSystemFileInfo);
    }

    public BusSystemFileInfo findById(Long id) {
        return busSystemFileInfoDao.selectByPrimaryKey(id);
    }
    
    public BusSystemFileInfo findByFileName(String name) {
        return busSystemFileInfoDao.findByFileName(name);
    }

    public List<BusSystemFileInfo> findAll() {
        return busSystemFileInfoDao.findByName("all");
    }

    public PageInfo<BusSystemFileInfo> findPage(String name, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<BusSystemFileInfo> all = busSystemFileInfoDao.findByName(name);
        return PageInfo.of(all);
    }
}
